package cn.itsuorce.controller;

import cn.itsuorce.domain.Shop;
import cn.itsuorce.query.ShopQuery;
import cn.itsuorce.service.IShopService;
import cn.itsuorce.utils.AjaxResult;
import cn.itsuorce.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ShopController {

    @Autowired
    private IShopService shopService;

    /**
     * 分页查询+高级查询，店铺
     *
     * @param shopQuery
     * @return
     * @RequestBody 表示从请求消息体中接收前端发送过来的json字符串，并且使用jackson工具包自动转化为所需要的实体类类型的对象
     */
    @PatchMapping("/shop")
    public AjaxResult page(@RequestBody ShopQuery shopQuery) {
        try {
            System.out.println(shopQuery);
            Page<Shop> page = shopService.findPage(shopQuery);
            return AjaxResult.me().setData(page);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("操作失败！" + e.getMessage());
        }
    }

    /**
     * 入驻审核
     * @param shop
     * @return
     */
    @PostMapping("/shop/audit")
    public AjaxResult audit(@RequestBody Shop shop){
        try {
            shopService.audit(shop);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("系统发生了错误！" + e.getMessage());
        }
    }

    /**
     * 激活
     * @param shop_id
     * @param employee_id
     * @return
     */
    @GetMapping("/shop/activation/{shop_id}/{employee_id}")
    public AjaxResult activation(@PathVariable("shop_id") Long shop_id,@PathVariable("employee_id") Long employee_id){
        try {
            shopService.activation(shop_id,employee_id);
            return AjaxResult.me().setMsg("激活成功");
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("操作失败"+e.getMessage());
        }

    }

}
